package kin.converter;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;   
import org.apache.commons.beanutils.BeanUtilsBean;  
  
/** 
 * @ClassName: ARPBeanUtils 
 * @Description: An extension of Apache common BeanUtils, can do the conversion 
 *               between POJOs with attributes of different generic type, like 
 *               from: InvoiceDTO-List<ChargeDTO> to 
 *               InvoiceBean-List<ChargeBean> 
 * @author ZHUGA3 
 * @date Sep 27, 2012 1:33:25 PM 
 *  
 */  
public final class ARPBeanUtils extends BeanUtils {  
  
    private static BeanUtilsBean utilBean = ARPBeanUtilsBean.getInstance();  
  
    public static void copyProperties(Object dest, Object orig) {  
        try {  
            utilBean.copyProperties(dest, orig);  
        } catch (Exception e) {  
            throw new RuntimeException(e);  
        }  
    }  
  
    /* 
     * a non-argument constructor must be supplied in destClass 
     */  
    public static <T> T cloneBean(Class<T> destClass, Object orig) {  
        try {  
            T dest = destClass.newInstance();  
            copyProperties(dest, orig);  
            return dest;  
        } catch (Exception e) {  
            throw new RuntimeException(e);  
        }  
    }  
    
    public static void copyProperty(Object bean, String name, Object value)
            throws IllegalAccessException, InvocationTargetException {

    	utilBean.copyProperty(bean, name, value);
        }
    
    
  }
